<!DOCTYPE html>
<html lang="en-US" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>1_程序控制语句 | XZ's Stack</title>
    
    <meta name="generator" content="VitePress v1.0.0-rc.29">
    <link rel="preload stylesheet" href="/xzstack/assets/style.Pz0Sdk2w.css" as="style">
    
    <script type="module" src="/xzstack/assets/app.qf8_2Tct.js"></script>
    <link rel="preload" href="/xzstack/assets/inter-roman-latin.bvIUbFQP.woff2" as="font" type="font/woff2" crossorigin="">
    <link rel="modulepreload" href="/xzstack/assets/chunks/framework.iD9JvHN-.js">
    <link rel="modulepreload" href="/xzstack/assets/chunks/theme.ZgCZhvpn.js">
    <link rel="modulepreload" href="/xzstack/assets/前端_原生_JS_1_程序控制语句.md.ei81aTFD.lean.js">
    <link rel="icon" href="./xz.png">
    <meta name="keywords" content="小张的栈">
    <meta name="description" content="文档主要是记录学习过程中的一些笔记、心得与感悟">
    <script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
    <script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-5a346dfe><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5a346dfe data-v-ae24b3ad><div class="VPNavBar has-sidebar" data-v-ae24b3ad data-v-d83f3580><div class="container" data-v-d83f3580><div class="title" data-v-d83f3580><div class="VPNavBarTitle has-sidebar" data-v-d83f3580 data-v-86d1bed8><a class="title" href="/xzstack/" data-v-86d1bed8><!--[--><!--]--><!----><!--[-->XZ&#39;s Stack<!--]--><!--[--><!--]--></a></div></div><div class="content" data-v-d83f3580><div class="curtain" data-v-d83f3580></div><div class="content-body" data-v-d83f3580><!--[--><!--]--><div class="VPNavBarSearch search" data-v-d83f3580><!----></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-d83f3580 data-v-7f418b0f><span id="main-nav-aria-label" class="visually-hidden" data-v-7f418b0f>Main Navigation</span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/xzstack/" tabindex="0" data-v-7f418b0f data-v-42ef59de><!--[--><span data-v-42ef59de>首页</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-9c007e85><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-9c007e85><span class="text" data-v-9c007e85><!----><span data-v-9c007e85>前端</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-9c007e85><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-9c007e85><div class="VPMenu" data-v-9c007e85 data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuLink" data-v-e7ea1737 data-v-43f1e123><a class="VPLink link" href="/xzstack/%E5%89%8D%E7%AB%AF/%E5%8E%9F%E7%94%9F/HTML/HTML%E5%9F%BA%E7%A1%80.html" data-v-43f1e123><!--[-->原生<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-e7ea1737 data-v-43f1e123><a class="VPLink link" href="/xzstack/%E5%89%8D%E7%AB%AF/%E6%A1%86%E6%9E%B6/Vue/Vue%E5%9F%BA%E7%A1%80.html" data-v-43f1e123><!--[-->框架<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-9c007e85><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-9c007e85><span class="text" data-v-9c007e85><!----><span data-v-9c007e85>专业基础</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-9c007e85><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-9c007e85><div class="VPMenu" data-v-9c007e85 data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuLink" data-v-e7ea1737 data-v-43f1e123><a class="VPLink link" href="/xzstack/%E4%B8%93%E4%B8%9A%E5%9F%BA%E7%A1%80/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/%E7%BB%AA%E8%AE%BA.html" data-v-43f1e123><!--[-->数据结构<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-9c007e85><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-9c007e85><span class="text" data-v-9c007e85><!----><span data-v-9c007e85>机器学习</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-9c007e85><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-9c007e85><div class="VPMenu" data-v-9c007e85 data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuLink" data-v-e7ea1737 data-v-43f1e123><a class="VPLink link" href="/xzstack/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E8%B7%AF%E7%BA%BF.html" data-v-43f1e123><!--[-->机器学习路线<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://gitee.com/xiangzhen-zhang" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-42ef59de><!--[--><span data-v-42ef59de>Gitee</span><!--]--></a><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://gitee.com/xiangzhen-zhang" target="_blank" rel="noreferrer" tabindex="0" data-v-7f418b0f data-v-42ef59de><!--[--><span data-v-42ef59de>Github</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-d83f3580 data-v-e6aabb21><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-e6aabb21 data-v-cbbe1149 data-v-b1685198><span class="check" data-v-b1685198><span class="icon" data-v-b1685198><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-cbbe1149><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-cbbe1149><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div><!----><div class="VPFlyout VPNavBarExtra extra" data-v-d83f3580 data-v-d0bd9dde data-v-9c007e85><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-9c007e85><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="icon" data-v-9c007e85><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg></button><div class="menu" data-v-9c007e85><div class="VPMenu" data-v-9c007e85 data-v-e7ea1737><!----><!--[--><!--[--><!----><div class="group" data-v-d0bd9dde><div class="item appearance" data-v-d0bd9dde><p class="label" data-v-d0bd9dde>Appearance</p><div class="appearance-action" data-v-d0bd9dde><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-d0bd9dde data-v-cbbe1149 data-v-b1685198><span class="check" data-v-b1685198><span class="icon" data-v-b1685198><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-cbbe1149><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-cbbe1149><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div></div></div><!----><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-d83f3580 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><!----></header><div class="VPLocalNav reached-top" data-v-5a346dfe data-v-f84a0989><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-f84a0989><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="menu-icon" data-v-f84a0989><path d="M17,11H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,11,17,11z"></path><path d="M21,7H3C2.4,7,2,6.6,2,6s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,7,21,7z"></path><path d="M21,15H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,15,21,15z"></path><path d="M17,19H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,19,17,19z"></path></svg><span class="menu-text" data-v-f84a0989>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-f84a0989 data-v-1c15a60a><button data-v-1c15a60a>Return to top</button><!----></div></div><aside class="VPSidebar" data-v-5a346dfe data-v-b00e2fdd><div class="curtain" data-v-b00e2fdd></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-b00e2fdd><span class="visually-hidden" id="sidebar-aria-label" data-v-b00e2fdd> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-b00e2fdd><div class="VPSidebarItem level-0" data-v-b00e2fdd data-v-e31bd47b><div class="item" role="button" tabindex="0" data-v-e31bd47b><div class="indicator" data-v-e31bd47b></div><p class="text" data-v-e31bd47b>HTML</p><!----></div><!----></div></div><div class="group" data-v-b00e2fdd><section class="VPSidebarItem level-0" data-v-b00e2fdd data-v-e31bd47b><div class="item" role="button" tabindex="0" data-v-e31bd47b><div class="indicator" data-v-e31bd47b></div><h2 class="text" data-v-e31bd47b>CSS</h2><!----></div><div class="items" data-v-e31bd47b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-e31bd47b data-v-e31bd47b><div class="item" data-v-e31bd47b><div class="indicator" data-v-e31bd47b></div><a class="VPLink link link" href="/xzstack/%E5%89%8D%E7%AB%AF/%E5%8E%9F%E7%94%9F/CSS/%E7%9B%92%E6%A8%A1%E5%9E%8B%E4%B8%8E%E5%AE%9A%E4%BD%8D.html" data-v-e31bd47b><!--[--><p class="text" data-v-e31bd47b>盒模型与定位</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-b00e2fdd><section class="VPSidebarItem level-0 has-active" data-v-b00e2fdd data-v-e31bd47b><div class="item" role="button" tabindex="0" data-v-e31bd47b><div class="indicator" data-v-e31bd47b></div><h2 class="text" data-v-e31bd47b>JS</h2><!----></div><div class="items" data-v-e31bd47b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-e31bd47b data-v-e31bd47b><div class="item" data-v-e31bd47b><div class="indicator" data-v-e31bd47b></div><a class="VPLink link link" href="/xzstack/%E5%89%8D%E7%AB%AF/%E5%8E%9F%E7%94%9F/JS/0_JavaScript%E5%9F%BA%E7%A1%80.html" data-v-e31bd47b><!--[--><p class="text" data-v-e31bd47b>JavaScript基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e31bd47b data-v-e31bd47b><div class="item" data-v-e31bd47b><div class="indicator" data-v-e31bd47b></div><a class="VPLink link link" href="/xzstack/%E5%89%8D%E7%AB%AF/%E5%8E%9F%E7%94%9F/JS/1_%E7%A8%8B%E5%BA%8F%E6%8E%A7%E5%88%B6%E8%AF%AD%E5%8F%A5.html" data-v-e31bd47b><!--[--><p class="text" data-v-e31bd47b>程序控制语句</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e31bd47b data-v-e31bd47b><div class="item" data-v-e31bd47b><div class="indicator" data-v-e31bd47b></div><a class="VPLink link link" href="/xzstack/%E5%89%8D%E7%AB%AF/%E5%8E%9F%E7%94%9F/JS/2_%E5%87%BD%E6%95%B0%E7%9A%84%E5%BA%94%E7%94%A8.html" data-v-e31bd47b><!--[--><p class="text" data-v-e31bd47b>函数的应用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e31bd47b data-v-e31bd47b><div class="item" data-v-e31bd47b><div class="indicator" data-v-e31bd47b></div><a class="VPLink link link" href="/xzstack/%E5%89%8D%E7%AB%AF/%E5%8E%9F%E7%94%9F/JS/3_%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%BA%94%E7%94%A8.html" data-v-e31bd47b><!--[--><p class="text" data-v-e31bd47b>对象的应用</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5a346dfe data-v-669faec9><div class="VPDoc has-sidebar has-aside" data-v-669faec9 data-v-6b87e69f><!--[--><!--]--><div class="container" data-v-6b87e69f><div class="aside" data-v-6b87e69f><div class="aside-curtain" data-v-6b87e69f></div><div class="aside-container" data-v-6b87e69f><div class="aside-content" data-v-6b87e69f><div class="VPDocAside" data-v-6b87e69f data-v-3f215769><!--[--><!--]--><!--[--><!--]--><div class="VPDocAsideOutline" role="navigation" data-v-3f215769 data-v-d330b1bb><div class="content" data-v-d330b1bb><div class="outline-marker" data-v-d330b1bb></div><div class="outline-title" role="heading" aria-level="2" data-v-d330b1bb>On this page</div><nav aria-labelledby="doc-outline-aria-label" data-v-d330b1bb><span class="visually-hidden" id="doc-outline-aria-label" data-v-d330b1bb> Table of Contents for current page </span><ul class="root" data-v-d330b1bb data-v-d0ee3533><!--[--><!--]--></ul></nav></div></div><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-6b87e69f><div class="content-container" data-v-6b87e69f><!--[--><!--]--><!----><main class="main" data-v-6b87e69f><div style="position:relative;" class="vp-doc _xzstack_%E5%89%8D%E7%AB%AF_%E5%8E%9F%E7%94%9F_JS_1_%E7%A8%8B%E5%BA%8F%E6%8E%A7%E5%88%B6%E8%AF%AD%E5%8F%A5" data-v-6b87e69f><div><h1 id="_1-程序控制语句" tabindex="-1">1_程序控制语句 <a class="header-anchor" href="#_1-程序控制语句" aria-label="Permalink to &quot;1_程序控制语句&quot;">​</a></h1><h2 id="条件判断语句" tabindex="-1">条件判断语句 <a class="header-anchor" href="#条件判断语句" aria-label="Permalink to &quot;条件判断语句&quot;">​</a></h2><h3 id="简单if语句" tabindex="-1">简单if语句 <a class="header-anchor" href="#简单if语句" aria-label="Permalink to &quot;简单if语句&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">if(表达式)</span></span>
<span class="line"><span style="color:#e1e4e8;">{</span></span>
<span class="line"><span style="color:#e1e4e8;">	语句块;</span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">if(表达式)</span></span>
<span class="line"><span style="color:#24292e;">{</span></span>
<span class="line"><span style="color:#24292e;">	语句块;</span></span>
<span class="line"><span style="color:#24292e;">}</span></span></code></pre></div><h3 id="if-else语句" tabindex="-1">if...else语句 <a class="header-anchor" href="#if-else语句" aria-label="Permalink to &quot;if...else语句&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">if (表达式){</span></span>
<span class="line"><span style="color:#e1e4e8;">	语句块1</span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span>
<span class="line"><span style="color:#e1e4e8;">else{</span></span>
<span class="line"><span style="color:#e1e4e8;">	语句块2</span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">if (表达式){</span></span>
<span class="line"><span style="color:#24292e;">	语句块1</span></span>
<span class="line"><span style="color:#24292e;">}</span></span>
<span class="line"><span style="color:#24292e;">else{</span></span>
<span class="line"><span style="color:#24292e;">	语句块2</span></span>
<span class="line"><span style="color:#24292e;">}</span></span></code></pre></div><h3 id="if-else-if语句" tabindex="-1">if ...else if语句 <a class="header-anchor" href="#if-else-if语句" aria-label="Permalink to &quot;if ...else if语句&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">if(expression1){</span></span>
<span class="line"><span style="color:#e1e4e8;">	block1;</span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span>
<span class="line"><span style="color:#e1e4e8;">else if(expression2){</span></span>
<span class="line"><span style="color:#e1e4e8;">	block2;</span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span>
<span class="line"><span style="color:#e1e4e8;">...</span></span>
<span class="line"><span style="color:#e1e4e8;">else{</span></span>
<span class="line"><span style="color:#e1e4e8;">	blockn;</span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">if(expression1){</span></span>
<span class="line"><span style="color:#24292e;">	block1;</span></span>
<span class="line"><span style="color:#24292e;">}</span></span>
<span class="line"><span style="color:#24292e;">else if(expression2){</span></span>
<span class="line"><span style="color:#24292e;">	block2;</span></span>
<span class="line"><span style="color:#24292e;">}</span></span>
<span class="line"><span style="color:#24292e;">...</span></span>
<span class="line"><span style="color:#24292e;">else{</span></span>
<span class="line"><span style="color:#24292e;">	blockn;</span></span>
<span class="line"><span style="color:#24292e;">}</span></span></code></pre></div><h3 id="if语句嵌套" tabindex="-1">if语句嵌套 <a class="header-anchor" href="#if语句嵌套" aria-label="Permalink to &quot;if语句嵌套&quot;">​</a></h3><h3 id="switch语句" tabindex="-1">switch语句 <a class="header-anchor" href="#switch语句" aria-label="Permalink to &quot;switch语句&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">switch(expression){</span></span>
<span class="line"><span style="color:#e1e4e8;">	case const1:</span></span>
<span class="line"><span style="color:#e1e4e8;">		block1;</span></span>
<span class="line"><span style="color:#e1e4e8;">		break;</span></span>
<span class="line"><span style="color:#e1e4e8;">	case const2:</span></span>
<span class="line"><span style="color:#e1e4e8;">		block2;</span></span>
<span class="line"><span style="color:#e1e4e8;">		break;</span></span>
<span class="line"><span style="color:#e1e4e8;">	...</span></span>
<span class="line"><span style="color:#e1e4e8;">	default:</span></span>
<span class="line"><span style="color:#e1e4e8;">    	block n+1;</span></span>
<span class="line"><span style="color:#e1e4e8;">    	break;</span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">switch(expression){</span></span>
<span class="line"><span style="color:#24292e;">	case const1:</span></span>
<span class="line"><span style="color:#24292e;">		block1;</span></span>
<span class="line"><span style="color:#24292e;">		break;</span></span>
<span class="line"><span style="color:#24292e;">	case const2:</span></span>
<span class="line"><span style="color:#24292e;">		block2;</span></span>
<span class="line"><span style="color:#24292e;">		break;</span></span>
<span class="line"><span style="color:#24292e;">	...</span></span>
<span class="line"><span style="color:#24292e;">	default:</span></span>
<span class="line"><span style="color:#24292e;">    	block n+1;</span></span>
<span class="line"><span style="color:#24292e;">    	break;</span></span>
<span class="line"><span style="color:#24292e;">}</span></span></code></pre></div><h2 id="循环语句" tabindex="-1">循环语句 <a class="header-anchor" href="#循环语句" aria-label="Permalink to &quot;循环语句&quot;">​</a></h2><h3 id="while语句" tabindex="-1">while语句 <a class="header-anchor" href="#while语句" aria-label="Permalink to &quot;while语句&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">while(expression)</span></span>
<span class="line"><span style="color:#e1e4e8;">{</span></span>
<span class="line"><span style="color:#e1e4e8;">	block;</span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">while(expression)</span></span>
<span class="line"><span style="color:#24292e;">{</span></span>
<span class="line"><span style="color:#24292e;">	block;</span></span>
<span class="line"><span style="color:#24292e;">}</span></span></code></pre></div><h3 id="do-while语句" tabindex="-1">do...while语句 <a class="header-anchor" href="#do-while语句" aria-label="Permalink to &quot;do...while语句&quot;">​</a></h3><blockquote><p>先执行循环体后判断循环条件，执行最小次数为1。</p></blockquote><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">do</span></span>
<span class="line"><span style="color:#e1e4e8;">{</span></span>
<span class="line"><span style="color:#e1e4e8;">	block;</span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span>
<span class="line"><span style="color:#e1e4e8;">while(expression);</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">do</span></span>
<span class="line"><span style="color:#24292e;">{</span></span>
<span class="line"><span style="color:#24292e;">	block;</span></span>
<span class="line"><span style="color:#24292e;">}</span></span>
<span class="line"><span style="color:#24292e;">while(expression);</span></span></code></pre></div><h3 id="for语句" tabindex="-1">for语句 <a class="header-anchor" href="#for语句" aria-label="Permalink to &quot;for语句&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">for(expression1;ex2;ex3)</span></span>
<span class="line"><span style="color:#e1e4e8;">{</span></span>
<span class="line"><span style="color:#e1e4e8;">	block;</span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">for(expression1;ex2;ex3)</span></span>
<span class="line"><span style="color:#24292e;">{</span></span>
<span class="line"><span style="color:#24292e;">	block;</span></span>
<span class="line"><span style="color:#24292e;">}</span></span></code></pre></div><h3 id="嵌套语句" tabindex="-1">嵌套语句 <a class="header-anchor" href="#嵌套语句" aria-label="Permalink to &quot;嵌套语句&quot;">​</a></h3><h2 id="跳转语句" tabindex="-1">跳转语句 <a class="header-anchor" href="#跳转语句" aria-label="Permalink to &quot;跳转语句&quot;">​</a></h2><h3 id="break语句" tabindex="-1">break语句 <a class="header-anchor" href="#break语句" aria-label="Permalink to &quot;break语句&quot;">​</a></h3><p>当break语句出现在一个循环内时，循环会立即终止，且程序将继续执行紧接着循环的下一条语句（当在内层循环，会跳出内层循环）。</p><h3 id="continue语句" tabindex="-1">continue语句 <a class="header-anchor" href="#continue语句" aria-label="Permalink to &quot;continue语句&quot;">​</a></h3><p>只终止本次循环，继续执行下一次循环，其后面的语句不再执行。</p></div></div></main><footer class="VPDocFooter" data-v-6b87e69f data-v-ef5dee53><!--[--><!--]--><!----><nav class="prev-next" data-v-ef5dee53><div class="pager" data-v-ef5dee53><a class="pager-link prev" href="/xzstack/%E5%89%8D%E7%AB%AF/%E5%8E%9F%E7%94%9F/JS/0_JavaScript%E5%9F%BA%E7%A1%80.html" data-v-ef5dee53><span class="desc" data-v-ef5dee53>Previous page</span><span class="title" data-v-ef5dee53>JavaScript基础</span></a></div><div class="pager" data-v-ef5dee53><a class="pager-link next" href="/xzstack/%E5%89%8D%E7%AB%AF/%E5%8E%9F%E7%94%9F/JS/2_%E5%87%BD%E6%95%B0%E7%9A%84%E5%BA%94%E7%94%A8.html" data-v-ef5dee53><span class="desc" data-v-ef5dee53>Next page</span><span class="title" data-v-ef5dee53>函数的应用</span></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>
    <script>window.__VP_HASH_MAP__=JSON.parse("{\"机器学习_机器学习路线.md\":\"Sz3n9Oge\",\"前端_框架_vue_vue基础.md\":\"5SjkgqQS\",\"前端_原生_css_盒模型与定位.md\":\"WAPmIZEg\",\"前端_原生_html_html基础.md\":\"3Nyts61A\",\"index.md\":\"qfen3ZYy\",\"前端_原生_js_1_程序控制语句.md\":\"ei81aTFD\",\"专业基础_数据结构_绪论.md\":\"TN3wzF3f\",\"前端_原生_js_0_javascript基础.md\":\"--KWmA7C\",\"前端_原生_js_2_函数的应用.md\":\"0-F8Psv5\",\"前端_原生_js_3_对象的应用.md\":\"fVjz36IU\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"XZ's Stack\",\"description\":\"A VitePress site\",\"base\":\"/xzstack/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"sidebar\":{\"/前端/原生\":[{\"text\":\"HTML\",\"items\":[]},{\"text\":\"CSS\",\"items\":[{\"text\":\"盒模型与定位\",\"link\":\"/前端/原生/CSS/盒模型与定位.md\"}]},{\"text\":\"JS\",\"items\":[{\"text\":\"JavaScript基础\",\"link\":\"/前端/原生/JS/0_JavaScript基础.md\"},{\"text\":\"程序控制语句\",\"link\":\"/前端/原生/JS/1_程序控制语句.md\"},{\"text\":\"函数的应用\",\"link\":\"/前端/原生/JS/2_函数的应用.md\"},{\"text\":\"对象的应用\",\"link\":\"/前端/原生/JS/3_对象的应用.md\"}]}],\"/前端/框架\":[{\"text\":\"Vue\",\"items\":[{\"text\":\"Vue基础\",\"link\":\"/前端/框架/Vue/Vue基础.md\"}]}],\"/机器学习/机器学习路线\":[{\"text\":\"机器学习路线\",\"items\":[{\"text\":\"机器学习路线\",\"link\":\"/机器学习/机器学习路线.md\"}]}],\"/专业基础/数据结构\":[{\"text\":\"数据结构\",\"items\":[{\"text\":\"绪论\",\"link\":\"/专业基础/数据结构/绪论.md\"},{\"text\":\"线性表\",\"link\":\"/前端/框架/Vue/Vue基础.md\"},{\"text\":\"栈、队列和数组\",\"link\":\"/前端/框架/Vue/Vue基础.md\"}]}]},\"nav\":[{\"text\":\"首页\",\"link\":\"/\"},{\"text\":\"前端\",\"items\":[{\"text\":\"原生\",\"link\":\"/前端/原生/HTML/HTML基础.md\"},{\"text\":\"框架\",\"link\":\"/前端/框架/Vue/Vue基础.md\"}]},{\"text\":\"专业基础\",\"items\":[{\"text\":\"数据结构\",\"link\":\"/专业基础/数据结构/绪论.md\"}]},{\"text\":\"机器学习\",\"items\":[{\"text\":\"机器学习路线\",\"link\":\"/机器学习/机器学习路线.md\"}]},{\"text\":\"Gitee\",\"link\":\"https://gitee.com/xiangzhen-zhang\"},{\"text\":\"Github\",\"link\":\"https://gitee.com/xiangzhen-zhang\"}]},\"locales\":{},\"scrollOffset\":90,\"cleanUrls\":false}");</script>
    
  </body>
</html>